class Solution {
public:
    string minWindow(string s, string t) {
        int kinds = 0;
        int n = s.size();
        int hash1[128] = { 0 };
        int hash2[128] = { 0 };
        for (auto& ch : t)
        {
            if (hash1[ch]++ == 0)
                kinds++;
        }
        int begin = -1, len = INT_MAX;
        for (int left = 0, right = 0, count = 0; right < n; right++)
        {
            if (++hash2[s[right]] == hash1[s[right]]) count++;
            while (count == kinds)
            {
                if (len > right - left + 1)
                {
                    begin = left;
                    len = right - left + 1;
                }
                if (hash2[s[left]] == hash1[s[left]])
                    count--;
                hash2[s[left]]--;
                left++;
            }
        }
        if (begin == -1)
            return "";
        else
            return s.substr(begin, len);

    }
};